From 65275eca3af4fb4bdd646ce152bfca25fbdbea9e Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sat, 19 Aug 2017 03:18:29 +0200 Subject: [PATCH] babl: get rid of RGB_LUMINANCE constants --- babl/babl-format.c | 2 +- babl/babl-space.c | 5 +++++ babl/babl.h | 4 ++++ babl/base/model-gray.c | 23 ++++++++++++++++++++++- babl/base/rgb-constants.h | 32 -------------------------------- extensions/grey.c | 22 +++++++++++++++------- 6 files changed, 47 insertions(+), 41 deletions(-) delete mode 100644 babl/base/rgb-constants.h diff --git a/babl/babl-format.c b/babl/babl-format.c index a2c8e17..6a7ebb2 100644 --- a/babl/babl-format.c +++ b/babl/babl-format.c @@ -104,7 +104,7 @@ format_new (const char *name, if (space == babl_space ("sRGB")) babl->format.model = model; else - babl->format.model = babl_remodel_with_space (model, space); + babl->format.model = (void*)babl_remodel_with_space ((void*)model, space); memcpy (babl->format.component, component, sizeof (BablComponent *) * components); memcpy (babl->format.type, type, sizeof (BablType *) * components); diff --git a/babl/babl-space.c b/babl/babl-space.c index 2d51d54..e6ef5ed 100644 --- a/babl/babl-space.c +++ b/babl/babl-space.c @@ -329,3 +329,8 @@ void babl_space_from_xyz (const Babl *space, const double *xyz, double *rgb) { _babl_space_from_xyz (space, xyz, rgb); } + +double * babl_space_get_rgbtoxyz (const Babl *space) +{ + return space->space.RGBtoXYZ; +} diff --git a/babl/babl.h b/babl/babl.h index c227703..e24640e 100644 --- a/babl/babl.h +++ b/babl/babl.h @@ -122,6 +122,10 @@ const Babl * babl_space_rgb_chromaticities (const char *name, const Babl *trc_green, const Babl *trc_blue); +double * babl_space_get_rgbtoxyz (const Babl *space); +void babl_space_to_xyz (const Babl *space, const double *rgb, double *xyz); +void babl_space_from_xyz (const Babl *space, const double *xyz, double *rgb); + /** * babl_format: * diff --git a/babl/base/model-gray.c b/babl/base/model-gray.c index 16b1811..36eff16 100644 --- a/babl/base/model-gray.c +++ b/babl/base/model-gray.c @@ -22,7 +22,6 @@ #include "babl-classes.h" #include "babl.h" #include "babl-ids.h" -#include "rgb-constants.h" #include "math.h" #include "babl-base.h" @@ -114,6 +113,11 @@ rgba_to_graya (Babl *conversion, char *dst, long n) { + const Babl *space = babl_conversion_get_source_space (conversion); + double RGB_LUMINANCE_RED = space->space.RGBtoXYZ[3]; + double RGB_LUMINANCE_GREEN = space->space.RGBtoXYZ[4]; + double RGB_LUMINANCE_BLUE = space->space.RGBtoXYZ[5]; + while (n--) { double red, green, blue; @@ -143,6 +147,11 @@ rgba_to_gray (Babl *conversion, char *dst, long n) { + const Babl *space = babl_conversion_get_source_space (conversion); + double RGB_LUMINANCE_RED = space->space.RGBtoXYZ[3]; + double RGB_LUMINANCE_GREEN = space->space.RGBtoXYZ[4]; + double RGB_LUMINANCE_BLUE = space->space.RGBtoXYZ[5]; + while (n--) { double red, green, blue; @@ -176,6 +185,10 @@ rgb_to_gray_2_2 (Babl *conversion, { const Babl *space = babl_conversion_get_destination_space (conversion); const Babl *trc = space->space.trc[0]; + double RGB_LUMINANCE_RED = space->space.RGBtoXYZ[3]; + double RGB_LUMINANCE_GREEN = space->space.RGBtoXYZ[4]; + double RGB_LUMINANCE_BLUE = space->space.RGBtoXYZ[5]; + BABL_PLANAR_SANITY while (n--) { @@ -352,6 +365,11 @@ rgba_to_gray_alpha_premultiplied (Babl *conversion, int *dst_pitch, long n) { + const Babl *space = babl_conversion_get_source_space (conversion); + double RGB_LUMINANCE_RED = space->space.RGBtoXYZ[3]; + double RGB_LUMINANCE_GREEN = space->space.RGBtoXYZ[4]; + double RGB_LUMINANCE_BLUE = space->space.RGBtoXYZ[5]; + BABL_PLANAR_SANITY; assert (src_bands == 4); assert (dst_bands == 2); @@ -450,6 +468,9 @@ rgba2gray_gamma_2_2_premultiplied (Babl *conversion, { const Babl *space = babl_conversion_get_destination_space (conversion); const Babl *trc = space->space.trc[0]; + double RGB_LUMINANCE_RED = space->space.RGBtoXYZ[3]; + double RGB_LUMINANCE_GREEN = space->space.RGBtoXYZ[4]; + double RGB_LUMINANCE_BLUE = space->space.RGBtoXYZ[5]; while (n--) { diff --git a/babl/base/rgb-constants.h b/babl/base/rgb-constants.h deleted file mode 100644 index 03810d6..0000000 --- a/babl/base/rgb-constants.h +++ /dev/null @@ -1,32 +0,0 @@ -/* babl - dynamically extendable universal pixel conversion library. - * Copyright (C) 2005, Øyvind Kolås. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, see - * . - */ - -/* - * These sRGB Y values have been adapted to the ICC spec D50 illuminant. - * They match the Y values in the GEGL and GIMP built-in sRGB profiles, - * which match the Y values in the ArgyllCMS sRGB.icm profile. - * - * For more information, see this thread and these bug reports: - * https://mail.gnome.org/archives/gimp-developer-list/2013-September/msg00113.html - * https://bugzilla.gnome.org/show_bug.cgi?id=723787 - * https://bugzilla.gnome.org/show_bug.cgi?id=724822 - */ - -#define RGB_LUMINANCE_RED (0.22248840) -#define RGB_LUMINANCE_GREEN (0.71690369) -#define RGB_LUMINANCE_BLUE (0.06060791) diff --git a/extensions/grey.c b/extensions/grey.c index b394064..f997dd8 100644 --- a/extensions/grey.c +++ b/extensions/grey.c @@ -22,7 +22,6 @@ #include "babl.h" #include "base/util.h" -#include "base/rgb-constants.h" #include "extensions/util.h" /* There was some debate on #gimp about whether these constants @@ -32,18 +31,17 @@ */ /* Float versions of the double constants in rgb-constants.h */ -static const float RGB_LUMINANCE_RED_FLOAT = RGB_LUMINANCE_RED; -static const float RGB_LUMINANCE_GREEN_FLOAT = RGB_LUMINANCE_GREEN; -static const float RGB_LUMINANCE_BLUE_FLOAT = RGB_LUMINANCE_BLUE; static long conv_rgbaF_linear_y8_linear (const Babl *conversion,unsigned char *src, unsigned char *dst, long samples) { - static const float RGB_LUMINANCE_RED_FLOAT = RGB_LUMINANCE_RED; - static const float RGB_LUMINANCE_GREEN_FLOAT = RGB_LUMINANCE_GREEN; - static const float RGB_LUMINANCE_BLUE_FLOAT = RGB_LUMINANCE_BLUE; + const Babl *space = babl_conversion_get_source_space (conversion); + double *rgbtoxyz = babl_space_get_rgbtoxyz (space); + const float RGB_LUMINANCE_RED_FLOAT = rgbtoxyz[3]; + const float RGB_LUMINANCE_GREEN_FLOAT = rgbtoxyz[4]; + const float RGB_LUMINANCE_BLUE_FLOAT = rgbtoxyz[5]; float *s = (float *) src; long n = samples; @@ -69,6 +67,11 @@ conv_rgbaF_linear_yF_linear (const Babl *conversion,unsigned char *src, unsigned char *dst, long samples) { + const Babl *space = babl_conversion_get_source_space (conversion); + double *rgbtoxyz = babl_space_get_rgbtoxyz (space); + const float RGB_LUMINANCE_RED_FLOAT = rgbtoxyz[3]; + const float RGB_LUMINANCE_GREEN_FLOAT = rgbtoxyz[4]; + const float RGB_LUMINANCE_BLUE_FLOAT = rgbtoxyz[5]; float *s = (float *) src; float *d = (float *) dst; @@ -92,6 +95,11 @@ conv_rgbaF_linear_yaF_linear (const Babl *conversion,unsigned char *src, unsigned char *dst, long samples) { + const Babl *space = babl_conversion_get_source_space (conversion); + double *rgbtoxyz = babl_space_get_rgbtoxyz (space); + const float RGB_LUMINANCE_RED_FLOAT = rgbtoxyz[3]; + const float RGB_LUMINANCE_GREEN_FLOAT = rgbtoxyz[4]; + const float RGB_LUMINANCE_BLUE_FLOAT = rgbtoxyz[5]; float *s = (float *) src; float *d = (float *) dst; -- 2.30.2